package com.example.demo.service;

import com.example.demo.entity.TableGoods;
import com.example.demo.entity.TableProduct;
import com.example.demo.mapper.TableGoodsMapper;
import com.example.demo.mapper.TableProductMapper;
import com.example.demo.utils.PageDataList;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class GoodsService {

    @Autowired
    private TableGoodsMapper tableGoodsMapper;



   public  PageDataList<TableGoods> getList(TableGoods usersDto){
       List<TableGoods> resultList = new ArrayList<>();
       PageHelper.startPage(usersDto.getPageNumber(), usersDto.getPageSize());
        List<TableGoods> dbResult = tableGoodsMapper.getList(usersDto);

        Page<TableGoods> dbResultPage = (Page<TableGoods>) dbResult;
        for (TableGoods dbItem : dbResultPage.getResult()) {
            resultList.add(dbItem);
        }

        PageDataList<TableGoods> pageDataList = new PageDataList<>(dbResultPage.getTotal(),
                dbResultPage.getPages(),
                dbResultPage.getPageNum(), dbResultPage.getPageSize());
        pageDataList.setList(resultList);
        return pageDataList;

    }




}
